package cn.dnui_yxk801.dnuifood_16110100801.controller;

import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;

import java.util.List;

import cn.dnui_yxk801.dnuifood_16110100801.Adapter.OrderAdapter;
import cn.dnui_yxk801.dnuifood_16110100801.R;
import cn.dnui_yxk801.dnuifood_16110100801.bean.CommentsBean;
import cn.dnui_yxk801.dnuifood_16110100801.listener.OnRetrofitListener;
import cn.dnui_yxk801.dnuifood_16110100801.model.UserModel;

import static cn.dnui_yxk801.dnuifood_16110100801.MainActivity.userid;

public class MyOrderActivity extends BaseActivity implements OnRetrofitListener{
    private RecyclerView rv_order;

    @Override
    void initViews() {
        layout_file=R.layout.activity_my_order;
        setLayout(layout_file);
        rv_order=findViewById(R.id.rv_order);
        RecyclerView.LayoutManager layoutManager = new LinearLayoutManager(this);
        // 设置布局管理器
        rv_order.setLayoutManager(layoutManager);
        //如果可以确定每个item的高度是固定的，设置这个选项可以提高性能
        rv_order.setHasFixedSize(true); //创建并设置Adapter
    }

    @Override
    void initEvents() {

    }

    @Override
    void initDatas() {
        UserModel userModel=new UserModel();
        userModel.getAllOrdersByUser(userid,this);
    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
    }

    @Override
    public void onSuccess(Object object, int flag) {
        if (flag==7){
            List list=(List<CommentsBean>)object;
            OrderAdapter orderAdapter=new OrderAdapter(MyOrderActivity.this,list);
            rv_order.setAdapter(orderAdapter);
        }
    }

    @Override
    public void onFalure(String msg) {

    }
}
